import pandas as pd
import json



map = {}
i = 0
# with open('../THUCNews/data/class1.txt', 'r', encoding='utf-8') as file: 
#     lines = file.readlines()
#     for line in lines:
#         line = line.replace('\n','')
#         map[i] = line
#         i = i+1


with open('../THUCNews/data/class1.txt', 'r', encoding='utf-8') as file: 
    lines = file.readlines()
    for line in lines:
        # if len(line)>1 :
          en, zh = line.split(' ',1)
          zh = zh.replace('\n','')
          map[en] = zh
    # print(list(map))      
  

res = []
with open('../../../../dataset/dev.json', 'r', encoding='utf-8') as file:
    # lines = file.readlines()
    samples = json.load(file)


    for pid, sample in samples.items(): 
        conversation = []
        system = {"role":"system","content":"你是一个文本分类器，请对以下医患对话行为分类，只能从以下列表选择一个分类，无需回答其他：[询问-病因,询问-预防措施,询问-治疗建议,告知-病因,诊断,询问-基本信息,询问-药物推荐,告知-治疗建议,询问-已有检查和治疗,告知-基本信息,告知-预防措施,告知-已有检查和治疗,告知-药物推荐,询问-症状,告知-症状,其他]"}
        conversation.append(system)
        for sent in sample['dialogue']:
            x = sent['speaker'] + '：' + sent['sentence']
            y = map.get(sent['dialogue_act'])
 
            user = {"role":"user","content": x}
            robot = {"role":"assistant","content":y}
            conversation.append(user)
            conversation.append(robot)
        contemp = {"conversations": conversation}
        res.append(contemp)





    # for line in lines:
    #     str1,str2 = line.split('\t',1)
    #     str2 = str2.replace('\n','')
    #     str2 = int(str2)
    #     content = "你是一个文本分类器，请对以下医患对话行为分类，只能从以下列表选择一个分类，无需回答其他：[询问-病因,询问-预防措施,询问-治疗建议,告知-病因,诊断,询问-基本信息,询问-药物推荐,告知-治疗建议,询问-已有检查和治疗,告知-基本信息,告知-预防措施,告知-已有检查和治疗,告知-药物推荐,询问-症状,告知-症状,其他]。'" + str1 +"',属于哪一类"
        
    #     tmp = {"conversations": [{"role": "user", "content": content},
    #     {"role": "assistant",
    #     "content":  map[str2] }]} 
    #     res.append(tmp)
    

with open('../THUCNews/data/paper-dev.json', mode='w',encoding='utf-8') as f:
    json_strings = [json.dumps(item,ensure_ascii=False,indent=None) + '\n' for item in res] 
    # json.dump(json_strings, f, ensure_ascii=False,indent=None)
    my_str = ' '.join(json_strings) 
    my_str = my_str.replace(" {","{")
    f.write(my_str)


